
$().ready(function() {
    validateRule();
});

$.validator.setDefaults({
    submitHandler : function() {
        save();
    }
});

function save() {
        $.ajax({
            cache : true,
            type : "POST",
            url : "/user/save",
            data : $('#signupForm').serialize(),// 你的formid
            async : false,
            error : function(request) {
                parent.layer.alert("Connection error");
            },
            success : function(data) {
                if (data.code == 0) {
                    parent.layer.msg("操作成功");
                    parent.reLoad();
                    var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                    parent.layer.close(index);
                } else {
                    parent.layer.alert(data.msg)
                }

            }
        });
}

//校验事件
function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#signupForm").validate({
        rules : {
            nickname : {
                required : true,
                minlength : 2
            },
            trueName : {
                required : true,
                minlength : 2
            },
            qqAccount : {
                required : true,
                digits : true,
                minlength : 5,
                maxlength : 10
            },
            weixinAccount : {
                required : true
            },
            email : {
                required : true,
                email : true
            },
            mobile : {
                required : true,
                minlength : 11,
                maxlength : 11
            }
        },
        messages : {

            nickname : {
                required : icon + "请输入昵称",
                minlength : icon + "昵称必须两个字符以上"
            },
            trueName : {
                required : icon + "请输入您的真实姓名",
                minlength : icon + "真实姓名必须两个字符以上"
            },
            qqAccount : {
                required : icon + "请输入您的QQ号码",
                digits : icon + "请输入正确的数字",
                minlength : icon + "QQ号码必须5位以上",
                maxlength : icon + "QQ号码必须10位以下"
            },
            weixinAccount : {
                required : icon + "请输入微信账号"
            },
            email : {
                required : icon + "请输入您的E-mail",
                email : icon + "请输入正确的E-mail格式",
            },
            mobile : {
                required : icon + "请输入您的手机号",
                minlength : icon + "手机号码必须为11位",
                maxlength : icon + "手机号码必须为11位"
            }
        }
    })
}